<!-- JSP to display all department details -->
<%@ page import="sg.edu.nus.iss.cats.model.Department,
                sg.edu.nus.iss.cats.controller.*,
                sg.edu.nus.iss.cats.dataaccess.DAOException"%>
<%@ include file="header.jsp" %>
<%@include file="departmentMenu.jsp" %>
<html>
<head>
    <title><fmt:message key="title.application"/></title>
    <link rel="STYLESHEET" type="text/css" href="<%= request.getContextPath() %>/css/style.css">
</head>



<h2>Current Department List</h2><br>
<% 
    Department[] departments = null;
    try{

        DepartmentManager departmentManager = new DepartmentManager();
        departments = departmentManager.findAllDepartments ();   
    }catch(DAOException e){
        HTMLUtil.displayException(request,response,"Sorry, the department details are not available.....");
        return;
            
    }

    if (departments==null){   
    
 %>
            
        <h3>Sorry, no departments found....</h3>
<%
        return;
     }else{

%>

        <table border=1 cellpadding=2 cellspacing=2>
        <tr><th>Department Id</th><th>Manager-In-Charge</th></tr>

        <%
        for (int i=0; i<departments.length;i++){

        %>
            <tr>
                <td>
                    <a href="<%= request.getContextPath() %>/admin/showModifyDept?departmentid=<%= departments[i].getDepartmentId() %>"><%= departments[i].getDepartmentId() %>
                    </a>
                </td>

                <td> 
                    <%= departments[i].getManagerInCharge() %>                               
                </td>
                <td>
                    <a href="<%= request.getContextPath() %>/admin/deleteDept?departmentid=<%= departments[i].getDepartmentId() %>" onClick=return confirm('Are you sure you want to remove this department?')>
                            <img src="<%= request.getContextPath() %>/img/delete.gif" border=0 alt="Delete department">
                    </a> 
                </td>
            </tr>

        <% } //end for

     } //end if %>
</table>


<%@ include file="footer.jsp" %>